﻿
CREATE PROCEDURE [dbo].[subreport_input_invoice_payemnts]
	(
	@p_invoice_in_id int,
	@p_date_from date,
	@p_date_to date
	)
AS
	SET NOCOUNT ON
	
SELECT     po.ID, po.NUMBER, po.[DATE], poi.SUM_RUB, poi.SUM_CUR, po.[DESCRIPTION], c.SHORT_NAME as CUR_NAME, c.CODE as CUR_CODE                      
FROM         PAYMENT_OUT as po
	INNER JOIN PAY_OUT_ON_INV_IN as poi
		ON po.ID = poi.PAYMENT_OUT_ID 
	INNER JOIN INVOICE_IN 
		ON poi.INVOICE_IN_ID = INVOICE_IN.ID 
	INNER JOIN NSI_CURRENCY as c
		ON INVOICE_IN.NSI_CURRENCY_ID = c.ID
WHERE     (poi.INVOICE_IN_ID = @p_invoice_in_id)
AND po.DATE between @p_date_from AND @p_date_to